package com.ruoyi.lm.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.lm.domain.LmSerinfotype;
import com.ruoyi.lm.service.ILmSerinfotypeService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 服务分类Controller
 * 
 * @author ruoyi
 * @date 2020-09-02
 */
@Controller
@RequestMapping("/phone/lm/serinfotype")
public class LmSerinfotypeControllerPhone extends BaseController
{
    private String prefix = "/phone/lm/serinfotype";

    @Autowired
    private ILmSerinfotypeService lmSerinfotypeService;

    /**
     * 查询服务分类列表
     */
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(LmSerinfotype lmSerinfotype)
    {
        List<Map> resultList = new ArrayList();
        //获取一级分类
        lmSerinfotype.setLevel("0");
        List<LmSerinfotype> list = lmSerinfotypeService.selectLmSerinfotypeList(lmSerinfotype);
        //获取对应的二级分类
        for(int i=0;i<list.size();i++){
            Map temp = new HashMap();
            temp.put("first",list.get(i));
            LmSerinfotype tempType =new LmSerinfotype();
            tempType.setFid(list.get(i).getId());
            temp.put("second",lmSerinfotypeService.selectLmSerinfotypeList(tempType));
            resultList.add(temp);
        }
        return getDataTable(resultList);
    }
    /**
     * 查询一级服务分类列表
     */
    @PostMapping("/listFirstLevel")
    @ResponseBody
    public TableDataInfo listFirstLevel(LmSerinfotype lmSerinfotype)
    {
        lmSerinfotype.setLevel("0");
        List<LmSerinfotype> list = lmSerinfotypeService.selectLmSerinfotypeList(lmSerinfotype);
        return getDataTable(list);
    }

    /**
     * 查询二级服务分类列表
     */
    @PostMapping("/listSecondLevel")
    @ResponseBody
    public TableDataInfo listSecondLevel(String id)
    {
        LmSerinfotype lmSerinfotype = new LmSerinfotype();
        lmSerinfotype.setFid(id);
        List<LmSerinfotype> list = lmSerinfotypeService.selectLmSerinfotypeList(lmSerinfotype);
        return getDataTable(list);
    }
}
